package StudyCode.summary.mycollection;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class RemoveAnElementFromCollectionUsingIterator {
	public static void main(String[] args) {
		ArrayList aList = new ArrayList();
		aList.add("1");
		aList.add("2");
		aList.add("3");
		aList.add("4");
		aList.add("5");


		System.out.println("ArrayList 移除前 : ");
		for (int i = 0; i < aList.size(); i++)
			System.out.println(aList.get(i));

		Iterator itr = aList.iterator();

		String strElement = "";
		while (itr.hasNext()) {
			strElement = (String) itr.next();
			if (strElement.equals("2")) {
				itr.remove();
				break;
			}
		}

		System.out.println("ArrayList 移除后 : ");
		for (int i = 0; i < aList.size(); i++)
			System.out.println(aList.get(i));
	}
}
